package com.tyk.bookstore.back.system.valid.validator;

import com.tyk.bookstore.back.common.core.valid.util.ValidUtil;
import com.tyk.bookstore.back.system.valid.annotation.PasswordValid;
import com.tyk.bookstore.back.system.valid.constant.UserValidConstant;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class PasswordConstraintValidator implements ConstraintValidator<PasswordValid, String> {

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		return value == null || ValidUtil.validString(value, UserValidConstant.PASSWORD_MIN_LENGTH,
				UserValidConstant.PASSWORD_MAX_LENGTH, UserValidConstant.PASSWORD_PATTERN);
	}

}
